#!/usr/bin/python
#=000
import sys, os #--
import pygst #--
pygst.require("0.10") #--
import gst #--
import pygtk #--
pygtk.require('2.0') #--
import gtk, gtk.glade #--
 #--
#=010 give elements names
#=011 audioconvert
PIPELINE = """
filesrc location=%s ! mad 
    ! audioconvert #011 
    ! ladspa-amPitchshift name=pitch  #010
    ! volume name=master #010
    ! audioconvert #011
    ! alsasink device=plughw:1
"""

class Pitch:
    def __init__(self):
        gladeFile = os.path.join(os.path.dirname(__file__,), 'pitch.glade') #--
        self.xml = gtk.glade.XML(gladeFile, None) #--
        self.xml.signal_autoconnect(self) #--
        window = self.xml.get_widget("main") #--
        window.connect('delete-event', gtk.main_quit) #--
        window.show_all() #--
#--
        self.pipeline = gst.parse_launch(PIPELINE % (sys.argv[1]))
#=020 get the two element objects
        self.master = self.pipeline.get_by_name('master') #020
        self.pitch = self.pipeline.get_by_name('pitch') #020

    def on_playButton_clicked(self, widget): #--
        # Start the pipeline #--
        self.pipeline.set_state(gst.STATE_PLAYING) #--
    def on_pauseButton_clicked(self, widget): #--
        # Pause the pipeline #--
        self.pipeline.set_state(gst.STATE_PAUSED) #--
    def on_quit_activate(self, widget): #--
        gtk.main_quit() #--
            
#=030 connect up a VScale or two...
    def on_masterScale_value_changed(self, w): #030
        scale = w.get_value()  #030
        self.master.set_property('volume', scale/100) #030
        
    def on_pitchScale_value_changed(self, w): #030
        scale = w.get_value()  #030
        # Scale is 0.25 -> 4 #030
        if scale < 0: scale = 0.25 + (3+scale) * 0.25 #030
        else: scale = 1 + scale #030
        self.pitch.set_property('Pitch-shift', scale) #030

if __name__ == "__main__":
    pitch=Pitch()
    gtk.main()
